import bus from "../bus/bus";

const skipMixin = {
  mounted() {
    let that = this;
    let box = document.getElementsByClassName("detailListBox")[0];
    if (box) {
      box.onmousemove = function(e) {
        if (e.target != this) {
          box.style.cursor = "auto";
          return;
        }
        e = e || window.event;
        if (e.stopPropagation) { //W3C阻止冒泡方法
          e.stopPropagation();
        } else {
          e.cancelBubble = true; //IE阻止冒泡方法
        }
        let boxY = e.offsetY;
        if (boxY <= 2) {
          box.style.cursor = "n-resize";
          box.onmousedown = (event) => {
            document.onmousemove = (ev) => {
              let changeBox = document.getElementsByClassName("detailBox")[0];
              let cbh = changeBox.offsetHeight;//要变动的dom高度
              let y = ev.clientY;//当前鼠标的位置
              let by = box.offsetTop;//距离浏览器顶部的距离
              changeBox.style.height = cbh - (by - y + 66) + "px";
              document.onmouseup = () => {
                let changeBox = document.getElementsByClassName("detailBox")[0];
                changeBox.scrollTop = 0;
                changeBox.scrollLeft = 0;
                document.onmousemove = null;
                box.onmousedown = null;
                document.onmouseup = null;
              };
            };
            document.onmouseup = () => {
              let changeBox = document.getElementsByClassName("detailBox")[0];
              changeBox.scrollTop = 0;
              changeBox.scrollLeft = 0;
              document.onmousemove = null;
              box.onmousedown = null;
              document.onmouseup = null;
            };
          };
        } else {
          box.onmousedown = (event) => {
            document.onmousemove = (ev) => {
              document.onmouseup = () => {
                document.onmousemove = null;
                box.onmousedown = null;
                document.onmouseup = null;
              };
            };
          };
        }
      };
    }

  },
  beforeDestroy() {
    let obj = {};
    if (Object.keys(this.$store.state.routeData).length !== 0) {
      obj["routeData"] = this.$store.state.routeData;
    }
    if (this.src) {
      obj["src"] = this.src;
    }
    if (this.$refs.detail) {
      let data = this.$refs.detail;
      if (data.newFlag) {
        obj["newFlag"] = data.newFlag;
      }
      if (data.src) {
        obj["src"] = data.src;
      }
      if (data.flag) {
        obj["detailFlag"] = data.flag;
      }
      if (data.temporary) {
        obj["detailTemporary"] = data.temporary;
      }
      obj["detail"] = data.detailData;
      obj["detailNav"] = data.detailNav;
      obj["routeData"] = data.selectData;
    }
    if (this.$refs.detailList) {
      let data = this.$refs.detailList;
      if (data.detailData) {
        obj["detailList"] = data.detailData;
      }
      if (data.src) {
        obj["src"] = data.src;
      }
      if (data.detailsFlag) {
        obj["detailListFlag"] = data.detailsFlag;
      }
      obj["detailListNav"] = data.detailNav;
    }
    this.$store.commit("setNewFlag", false);
    bus.$emit("setTopSideData", obj);
  }
};
export default skipMixin;
